# -*- coding: utf-8 -*-
# @Time    : 2023/6/2 22:23
# @Author  : hy
# @Email   : 1596096369@qq.com
# @File    : driver.py
# @Software: PyCharm
from appium import webdriver
from tools.get_device import get_android,get_device
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from appium.options.common.base import AppiumOptions
def app():
    desired_capabilities = {
        'platformName': 'Android',
        'deviceName': get_device(),
        'platformVersion': get_android(),
        'appPackage': 'com.xiachufang',
        'appActivity': 'com.xiachufang.activity.home.HomeActivity',
        'noReset': True
    }
    options = AppiumOptions()
    options.load_capabilities(desired_capabilities)
    driver = webdriver.Remote('http://localhost:4723/wd/hub', options=options)
    add_locater = (By.XPATH, '//*[@resource-id="com.xiachufang:id/tab_widget_content_create"]')
    wait = WebDriverWait(driver, 20, 0.5)
    wait.until(EC.presence_of_all_elements_located(add_locater))
    return driver

